<?php
class Email{
	
	public $emailTo;
	public $nameTo;
	public $emailFrom;
	public $nameFrom;
	public $subject;
	public $anexo;
	public $body;
	public $mail;
	
	public function __construct($emailTo = "" , $nameTo = "", $emailFrom = "", $nameFrom = "", $subject = "", $anexo = ""){
		$this->emailTo	= $emailTo;
		$this->nameTo   = $nameTo;
		$this->subject 	= $subject;
		$this->anexo 	= $anexo;
		$this->emailFrom = $emailFrom;
		$this->nameFrom = $nameFrom;
	}
	
	public function __destruct(){}
	
	function loadTemplate($strPath, $dadosEmail){
		if (!file_exists($strPath)) { 
			die('arquivo nao existe');
		}
		$this->body = join ("",file($strPath));
		foreach ($dadosEmail as $k=>$v) {
			$this->body = str_replace ($k,$v,$this->body);
		}
	}
	public function send(){
		$this->mail = new PHPMailer();
		$this->mail->IsSMTP();
		$this->mail->Host = "smtp.ananke.com.br";
		$this->mail->SMTPAuth = false;
		$this->mail->Username = "if_apply";
		$this->mail->Password = "if_apply";
		$this->mail->From = $this->emailFrom;
		$this->mail->FromName = $this->nameFrom;

		$this->mail->IsHTML(true);
		
		$headers =  "From: {$this->emailFrom}\r\n";
		$headers .= "X-Sender: {$this->emailFrom}\r\n";
		$headers .= "Return_path: {$this->emailFrom}\r\n";
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1";
		$this->mail->AddCustomHeader($headers);
		
		if($this->emailTo){
			$nomes = explode(",",$this->nameTo);
	 		foreach(explode(",",$this->emailTo) as $key=>$email){
	 			$nome = (!empty($nomes) && isset($nomes[$key])) ? $nomes[$key] : "" ;
	 			$this->mail->AddAddress($email,$nome);
	 		}
		}
	 	if($this->anexo){
	 		$anexos = explode(",",$this->anexo);
	 		foreach($anexos as $anexo)
	 			$this->mail->AddAttachment($anexo);
	 	}
	 	$this->mail->Subject  = $this->subject;  
	 	$this->mail->Body  = $this->body;
	 	
		if(!$this->mail->Send()) return false;
		return true;
	}
}
?>